import unittest
from unittestreport import ddt, list_data, json_data, yaml_data

# cases_data = [{"title": "测试10加20是否等于31", "data":{"num1":10, "num2":20}, "expected":31},
#               {"title": "测试1加20是否等于21", "data":{"num1":1, "num2":20}, "expected":21},
#               {"title": "测试10加2是否等于12", "data":{"num1":10, "num2":2}, "expected":12},]

def add(a, b):
    return a+b

@ddt
class TestDemo4(unittest.TestCase):

    # @list_data(cases_data)
    # @json_data(r'C:\TT\习知\自动化代码-4期\unittestDemo\cases_json.json')
    @yaml_data(r'C:\TT\习知\自动化代码-4期\unittestDemo\case_yaml.yaml')
    def test_01(self, data):
        num1 = data.get("data").get("num1")
        num2 = data.get("data").get("num2")
        sum_num = data.get("expected")
        value = add(num1, num2)
        self.assertEqual(sum_num, value)

    # def test_02(self):
    #     num1 = 1
    #     num2 = 20
    #     sum_num = 21
    #     value = add(num1, num2)
    #     self.assertEqual(sum_num, value)

if __name__ == '__main__':
    unittest.main()